using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Straw : MonoBehaviour
{
    public enum MyEnum {Straw,vat };
    public MyEnum Straw_type;

    private bool hasCollided = false;
    public GameObject BrokenStraw;
    public GameObject BrokenP;
    // Start is called before the first frame update
    void Start()
    {
        BrokenP = GameObject.Find("BrokenGameObject").transform.gameObject;

    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Bullet" || other.gameObject.tag == "PlaySkill1" || other.gameObject.tag == "PlaySkill2" 
            || other.gameObject.tag == "TrapMagic"|| other.gameObject.tag == "Explosion")
        {
            if (!hasCollided)
            {
                hasCollided = true;
                creatBrokenStraw();
                Destroy(gameObject);

            }
        }

    }
    void creatBrokenStraw()
    {
        if(Straw_type==MyEnum.Straw)
        {
            GameObject warn = Instantiate(BrokenStraw);
            warn.transform.SetParent(BrokenP.transform);
            warn.transform.position = gameObject.transform.position;
        }
        else if(Straw_type==MyEnum.vat)
        {
            GameObject warn = Instantiate(BrokenStraw);
            warn.transform.SetParent(BrokenP.transform);
            warn.transform.position = gameObject.transform.position-transform.up;
        }
    }
}
